<?php
/**
 * 未完成医嘱数据拉取
 * @authors xiadx (xiadx@zpdchina.com)
 * @date    2017-03-08 13:49:21
 * @version $Id$
 */

class GetUnworkYizhuDataJsonController extends Yaf_Controller_Abstract {

    public function indexAction()
    {
    	$request = $this->getRequest();
    	// 科室名称
    	$user_department = $request->getPost('user_department', '');
        if($user_department == "")
        {
            Utility::apiJsonError(20031, '科室不能为空');
        }
    	// 科室ID
    	//$user_department_id = $request->getPost('user_department_id', '');
    	// 修改时间
    	$yiyuan_id = $request->getPost('yiyuan_id',0);
    	// 指定医嘱id
    	$json_data_str = $request->getPost('data', '');
    	$compression_http_data = $request->getPost('compression_http_data', 'off');
		// 解压缩数据
    	$json_data = json_decode(Utility::uncompress($json_data_str, $compression_http_data));
    	$time = intval (date("Hi"));
    	$show_lishi_yizhu = Yaconf::get("config$yiyuan_id.show_lishi_yizhu");
    	if($time <= intval($show_lishi_yizhu)){
	    	$yizhu_unwork_mod = new ZhuyuanYizhuUnworkModel;
	    	$data = $yizhu_unwork_mod->ls($user_department, $json_data);
	        $async_result['msg'] = '';
	    	if (empty($data)) {
	            $async_result['msg'] = '暂无数据!';
	    	}
	    	$field_arr = $yizhu_unwork_mod->_field_arr;
	    	$async_result['update_sql'] = Utility::formatToSqlStrExtends($data, 'yizhu_unwork_info', 'update_sql',$field_arr);
    	}else{
    		$async_result['update_sql'][] = "delete from yizhu_unwork_info";;
    	}
    	$async_result['error'] = 200;
        $async_result['msg'] = '';
    	Utility::apiJsonResultExtends($async_result);
    }
}
